// miniprogram/pages/home/success/index.js

var app = getApp();
var api = require('../../../utils/api');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    imageUrl: app.globalData.imageUrl,
    blessResult: {
      seq: 1,
      words: [],
    },
    userData: {

    },
    playMusic: 0,
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.initMod(this);
    let self = this;
    api.getBlessRoundInfo().then(roundInfoResult => {
      console.log(roundInfoResult);
      if (roundInfoResult.code != 0 || !Array.isArray(roundInfoResult.data.blessResult.words) || roundInfoResult.data.blessResult.words.length == 0) {
        app.text('祈福信息查询失败');
        console.log('bless round info request catch err, code=' + roundInfoResult.result.code);
        wx.redirectTo({
          url: '/pages/home/index/index',
        });
      }
      self.setData({
        blessResult: roundInfoResult.data.blessResult,
      });
    }).catch(err => {
      app.text('祈福信息查询失败');
      console.log('bless round info request catch exception, err=' + err);
      wx.redirectTo({
        url: '/pages/home/index/index',
      });
    });
    console.log(this.data.blessResult);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return console.log(app.globalData.imageUrl + "/home/index/bg1.jpg"), {
      title: "云撞钟  共祈福",
      path: "/pages/home/index/index?user_id=" + this.data.userData.id,
      imageUrl: app.globalData.imageUrl + "/home/index/bg1.jpg",
      success: function (a) {
        app.text("成功");
      }
    };
  },

  playMusic: function (e) {
    app.playMusic(this, e);
  },

  getPoster: function () {
    var a = this.data.datas;
    wx.setStorageSync("templeDatas", a);
    var e = JSON.stringify(a);
    console.log(e);
    e = encodeURIComponent(e);
    app.navigateTo("/pages/home/templePoster/index?datas=" + e);
  },

  toUser: function () {
    app.redirectTo("/pages/user/goodsList/index");
  },

  onHide: function () {
    app.globalData.playMusic && wx.setStorageSync("music", 1);
  },
})